package com.yanqu.road.server.cmd.activity.douluodalu;


import com.yanqu.road.pb.activity.douluodalu.DouLuoDaLuProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.VipMgr;
import com.yanqu.road.server.manger.activity.douluodalu.DouLuoDaLuMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_DOU_LUO_DA_LU_ONE_KEY_FIGHT,desc = "一键挑战(自动打完剩余进度)")
public class DouLuoDaLuOneKeyFightCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if ((ret = DouLuoDaLuMgr.canEntryActivity(player)) != 0) return;

        if ((ret = DouLuoDaLuMgr.activityInDuiJuePeriod()) != 0) return;

        DouLuoDaLuProto.DouLuoDaLuAutoBattleReqMsg reqMsg = DouLuoDaLuProto.DouLuoDaLuAutoBattleReqMsg.parseFrom(packet.getBytes());

        DouLuoDaLuProto.DouLuoDaLuAutoBattleCrossReqMsg.Builder crossReq = DouLuoDaLuProto.DouLuoDaLuAutoBattleCrossReqMsg.newBuilder();
        crossReq.setActivityId(DouLuoDaLuMgr.getActivityInfo().getActivityId());
        crossReq.setAutoBuy(reqMsg.getAutoBuy());
        if(reqMsg.hasBuyItem()) {
            crossReq.setBuyItem(reqMsg.getBuyItem());
        }else {
            crossReq.setBuyItem(0);
        }
        if(reqMsg.hasPercent()) {
            crossReq.setPercent(reqMsg.getPercent());
        }else {
            crossReq.setPercent(0);
        }
        int vipLv = VipMgr.getVipLv(player.getUserInfo().getVipExp());
        crossReq.setVipLv(vipLv);
        player.sendUnionActivityGroupPacket(Protocol.C_DOU_LUO_DA_LU_ONE_KEY_FIGHT, crossReq, crossReq.getActivityId());
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_DOU_LUO_DA_LU_ONE_KEY_FIGHT, DouLuoDaLuProto.DouLuoDaLuAutoBattleRespMsg.newBuilder().setRet(ret));
        }
    }
}
